﻿//using System;
//using System.Diagnostics;
//using System.ServiceModel;
//using System.ServiceModel.Description;
//using System.ServiceModel.Discovery;
//using EasyComm.Utilities;

//namespace EasyComm.Hosting.Configuration
//{
//    internal static class ModuleConfiguration
//    {
//        internal static void ApplyConfiguration(ServiceHost serviceHost, Type serviceType, Uri[] baseAddresses, Uri SLBDiscoveryProxyAddress, Uri NLBDiscoveryProxyAddress, Type contractType = null, string ns = "http://www.tempuri.org/")
//        {
//            if (serviceHost == null)
//            {
//                return;
//            }
//            ContractDescription desc = ContractDescription.GetContract(contractType, serviceType);// GenericConfiguration.CreateContractDescription(serviceType, contractType, ns); //new ContractDescription("EasyComm.WorkerService.IWorkerService");

//            #region main endpoints
//            for (int i = 0; i < baseAddresses.Length; i++)
//            {
//                ServiceEndpoint mainEndPoint = new ServiceEndpoint(desc, GenericConfiguration.GetMainBinding(), new EndpointAddress(baseAddresses[i]));
//                mainEndPoint.Name = string.Format("{0}_MainEndpoint_{1}", serviceType.Name, i);
//                serviceHost.AddServiceEndpoint(mainEndPoint);
//            }
//            #endregion

//            // ** DISCOVERY ** //
//            ServiceDiscoveryBehavior discoveryBehavior = new ServiceDiscoveryBehavior();
//            serviceHost.Description.Behaviors.Add(discoveryBehavior);
//            serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint() { Name = "udpDiscoveryEndPoint" });
//            discoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());

//            if (NetUtils.TCPOnlineCheck(NLBDiscoveryProxyAddress.Host, NLBDiscoveryProxyAddress.Port))
//            {
//                AnnouncementEndpoint nlbAnnouncementEndpoint = new AnnouncementEndpoint(GenericConfiguration.GetAnnouncementBinding(), new EndpointAddress(NLBDiscoveryProxyAddress.ToString()));
//                discoveryBehavior.AnnouncementEndpoints.Add(nlbAnnouncementEndpoint);
//            }
//            else
//            {
//                Trace.WriteLine("NLB Proxy server is offline. Bypassing registration for proxy announcements.");
//            }

//            if (NetUtils.TCPOnlineCheck(SLBDiscoveryProxyAddress.Host, SLBDiscoveryProxyAddress.Port))
//            {
//                AnnouncementEndpoint slbAnnouncementEndpoint = new AnnouncementEndpoint(GenericConfiguration.GetAnnouncementBinding(), new EndpointAddress(SLBDiscoveryProxyAddress.ToString()));
//                discoveryBehavior.AnnouncementEndpoints.Add(slbAnnouncementEndpoint);
//            }
//            else
//            {
//                Trace.WriteLine("SLB Proxy server is offline. Bypassing registration for proxy announcements.");
//            }

//            GenericConfiguration.SetupMex(serviceHost, serviceType);
//            GenericConfiguration.SetupDebugging(serviceHost);
//            //System.ServiceModel.ServiceHostingEnvironment.MultipleSiteBindingsEnabled = true;
//        }
//    }
//}
